list-[id].vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation></HomePageNavigation>
  7. <!-- 二级标题-->
  8. <!--<div class="sannongzhichuang" v-if="parent_name != ''">
  9. <div class="inner">
  10. <h2>
  11. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  12. <em class="iconfont icon-xingzhuang-zhijiaosanjiaoxing-copy"></em>
  13. </h2>
  14. <p class="introduction">
  15. <strong>频道介绍</strong>
  16. <div v-for="(item, index) in secondNav" :key="index">
  17. <span v-if="index <= 7">
  18. <NuxtLink :to="{ path: `/${item.aLIas_pinyin}/list-1.html`}">{{ item.alias }}</NuxtLink>
  19. </span>
  20. <b v-else></b>
  21. </div>
  22. </p>
  23. </div>
  24. </div>-->
  25. <!-- 面包屑导航 -->
  26. <div class="breadcrumb-box">
  27. <div class="inner">
  28. <span class="location">当前位置:</span>
  29. <el-breadcrumb :separator-icon="ArrowRight">
  30. <el-breadcrumb-item>
  31. <NuxtLink to="/">首页</NuxtLink>
  32. </el-breadcrumb-item>
  33. <el-breadcrumb-item v-if="parent_name !=''">
  34. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  35. </el-breadcrumb-item>
  36. <el-breadcrumb-item>{{ name }}</el-breadcrumb-item>
  37. </el-breadcrumb>
  38. </div>
  39. </div>
  40. <!-- 资讯列表 -->
  41. <div class="newsList">
  42. <div class="listBox">
  43. <div class="listBoxLeft">
  44. <ul class="list">
  45. <li v-for="(item, index) in newsList" :key="index">
  46. <NuxtLink :href="getLinkPathDetail(item)" :title="item.alias">
  47. {{ item.title }}
  48. </NuxtLink>
  49. <p>
  50. <NuxtLink :href="getLinkPathDetail(item)" :title="item.alias">
  51. {{ item.title }}
  52. </NuxtLink>
  53. </p>
  54. </li>
  55. </ul>
  56. <!-- 分页器 -->
  57. <div class="pagination" v-if="total > 0">
  58. <el-pagination
  59. size="small"
  60. background
  61. layout="prev, pager, next"
  62. :total="total"
  63. class="mt-4"
  64. :page-size="pageSize"
  65. :current-page="pageNum"
  66. prev-text="上一页"
  67. next-text="下一页"
  68. @current-change="changePage"
  69. />
  70. <span class="total">共{{ total }}条</span>
  71. </div>
  72. </div>
  73. <div class="listBoxRight">
  74. <!-- <DetailHotNews></DetailHotNews> -->
  75. <DetailHotNews2></DetailHotNews2>
  76. </div>
  77. </div>
  78. </div>
  79. <!-- 页面底部 -->
  80. <HomeFoot></HomeFoot>
  81. </div>
  82. </template>
  83. <script setup>
  84. //1.页面必备依赖 start ---------------------------------------->
  85. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  86. import { ArrowRight } from '@element-plus/icons-vue'
  87. import { ref, onMounted } from 'vue';
  88. //当前列表名称
  89. const name = ref('')
  90. const { $webUrl, $CwebUrl, $BwebUrl } = useNuxtApp()
  91. //格式化跳转路径
  92. const getLinkPathDetail = (item) => {
  93. if (item.islink == 1) {
  94. return `${item.linkurl}`;
  95. } else {
  96. //return `/${item.aLIas_pinyin}/${item.id}`;
  97. //return `/newsDetail/${item.id}`
  98. return `/${item.pinyin}/${item.id}.html`;
  99. }
  100. }
  101. //1.页面必备依赖 end ---------------------------------------->
  102. //1.获得路由id start ---------------------------------------->
  103. const route = useRoute();
  104. let articleId = 0;//路由id
  105. let pageNum = ref(2);
  106. let total = ref(1);
  107. let pageSize = ref(10);
  108. //获得当前的完整路径
  109. const fullPath = route.path;
  110. //拆分,取出来中间这一段,然后提取数字部分
  111. const segments = fullPath.split('/');
  112. const targetSegment = segments[1];
  113. //const numberPart = targetSegment.match(/\d+$/)?.[0];
  114. //let routeId = 20 //排除路径错误可以打开这个
  115. //通过导航路径反向查询导航id
  116. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  117. method: 'GET',
  118. query: {
  119. 'pinyin': targetSegment,
  120. },
  121. });
  122. if(getRouteId.code == 200){
  123. articleId = getRouteId.data.category_id
  124. }else{
  125. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  126. console.log("错误位置:通过url路径查询导航池id")
  127. console.log("后端错误反馈:",getRouteId.message)
  128. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  129. }
  130. //获得html前的数字
  131. // const pageUrl = segments[2];
  132. // const pageNumber = pageUrl.split('.')[0];
  133. // console.log("当前URL中的页码:")
  134. // console.log(pageNumber)//2
  135. // pageNum.value = parseInt(pageNumber);
  136. pageNum.value = parseInt(route.params.id);
  137. //1.获得路由id end ---------------------------------------->
  138. //2.页面数据 start ---------------------------------------->
  139. //2.2新闻列表
  140. const newsList = ref([]);
  141. let newslists = async () => {
  142. const listData = await requestDataPromise('/web/getWebsiteArticleList', {
  143. method: 'GET',
  144. query: {
  145. 'page': pageNum.value,
  146. 'pageSize': pageSize.value,
  147. 'catid': articleId
  148. },
  149. });
  150. if (listData.code == 200) {
  151. newsList.value = listData.data.rows;
  152. total.value = listData.data.count;
  153. } else {
  154. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  155. // console.log("错误位置:获取新闻列表")
  156. // console.log("后端错误反馈:", listData.message)
  157. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  158. }
  159. }
  160. //获得列表
  161. newslists();
  162. //分页事件
  163. let changePage = (value) => {
  164. console.log("当前页码", value);
  165. navigateTo(`/${targetSegment}/list-${value}.html`)
  166. }
  167. //2.3获得页面名称
  168. let getPageName = async () => {
  169. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  170. method: 'GET',
  171. query: {
  172. 'catid': articleId
  173. },
  174. });
  175. if (pageName.code == 200) {
  176. name.value = pageName.data.alias
  177. } else {
  178. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  179. // console.log("错误位置:设置页面标题")
  180. // console.log("后端错误反馈:", pageName.message)
  181. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  182. }
  183. }
  184. //获得列表
  185. getPageName();
  186. //2.页面数据 end ---------------------------------------->
  187. //3.二级栏目 start ---------------------------------------->
  188. //3.1通过id获取父栏目
  189. const parent_name = ref([]);
  190. const parent_id = ref([]);
  191. const parent_pinyin = ref("");
  192. let getParentNav = async () => {
  193. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  194. method: 'GET',
  195. query: {
  196. 'catid': articleId
  197. },
  198. });
  199. if (listData.code == 200) {
  200. console.log(111999)
  201. console.log(listData.data);
  202. parent_name.value = listData.data.parent_name;
  203. parent_id.value = listData.data.parent_id;
  204. parent_pinyin.value = listData.data.parent_pinyin;
  205. } else {
  206. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  207. // console.log("错误位置:获取新闻列表")
  208. // console.log("后端错误反馈:", listData.message)
  209. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  210. }
  211. getSecondNav();
  212. }
  213. //获得列表
  214. getParentNav();
  215. // 3.2获取二级栏目
  216. const secondNav = ref([]);
  217. let getSecondNav = async () => {
  218. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  219. method: 'GET',
  220. query: {
  221. 'placeid': 1,
  222. 'pid': parent_id.value,
  223. 'num': 8,
  224. },
  225. });
  226. console.log('listData', listData);
  227. if (listData.code == 200) {
  228. secondNav.value = listData.data
  229. } else {
  230. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  231. console.log("错误位置:获取新闻列表")
  232. console.log("后端错误反馈:", listData.message)
  233. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  234. }
  235. }
  236. //3.二级栏目 end ---------------------------------------->
  237. //4.设置seo信息 start---------------------------------------->
  238. //4.1 设置seo信息
  239. const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
  240. method: 'GET',
  241. query: {
  242. 'catid': articleId
  243. },
  244. });
  245. if (setData.code == 200) {
  246. let seoTitle = setData.data.seo_title;
  247. let seoDescription = setData.data.seo_description;
  248. let seoKeywords = setData.data.seo_keywords;
  249. let seoSuffix = setData.data.suffix;
  250. let seoName = setData.data.website_name;
  251. useSeoMeta({
  252. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  253. meta: [
  254. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  255. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  256. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  257. ]
  258. });
  259. } else {
  260. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  261. // console.log("错误位置:设置列表页面SEO数据")
  262. // console.log("后端错误反馈:", setData.message)
  263. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  264. }
  265. //4.设置seo信息 end---------------------------------------->
  266. //5.广告 start---------------------------------------->
  267. let adImg1 = ref({});
  268. let adImg2 = ref({});
  269. onMounted(async () => {
  270. //从客户端获取行政职能部门 加快打开速度
  271. const { $webUrl, $CwebUrl } = useNuxtApp();
  272. //广告1
  273. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_list_0001`
  274. const responseAd1 = await fetch(url, {
  275. headers: {
  276. 'Content-Type': 'application/json',
  277. 'Userurl': $CwebUrl,
  278. 'Origin': $CwebUrl
  279. }
  280. });
  281. const resultAd1 = await responseAd1.json();
  282. adImg1.value = resultAd1.data[0];
  283. //广告2
  284. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_list_0002`
  285. const responseAd2 = await fetch(url2, {
  286. headers: {
  287. 'Content-Type': 'application/json',
  288. 'Userurl': $CwebUrl,
  289. 'Origin': $CwebUrl
  290. }
  291. });
  292. const resultAd2 = await responseAd2.json();
  293. adImg2.value = resultAd2.data[0];
  294. })
  295. //5.广告 end---------------------------------------->
  296. </script>
  297. <style lang="less" scoped>
  298. // @import url('@/assets/css/list/pc.less');
  299. // @import url('@/assets/css/list/yd.less');
  300. //面包屑
  301. .breadcrumb-box {
  302. width: 1400px;
  303. margin: 0 auto;
  304. .inner {
  305. width: 100%;
  306. height: 22px;
  307. margin-top: 20px;
  308. margin-bottom: 20px;
  309. font-family: Microsoft YaHei, Microsoft YaHei;
  310. font-weight: 400;
  311. font-size: 20px;
  312. color: #666666;
  313. line-height: 23px;
  314. text-align: left;
  315. font-style: normal;
  316. text-transform: none;
  317. display: flex;
  318. align-items: center;
  319. border-bottom: 1px dashed #ccc;
  320. margin-bottom: 10px;
  321. padding: 20px 20px 20px 0;
  322. box-sizing: border-box;
  323. a {
  324. font-size: 16px;
  325. color: #000;
  326. line-height: 20px;
  327. }
  328. span {
  329. font-size: 16px;
  330. color: #000;
  331. line-height: 20px;
  332. &.location {
  333. line-height: 20px;
  334. }
  335. }
  336. }
  337. }
  338. //资讯列表
  339. .newsList {
  340. width: 1400px;
  341. margin: 0 auto;
  342. .listBox {
  343. display: flex;
  344. align-items: flex-start;
  345. justify-content: space-between;
  346. .listBoxLeft {
  347. width: 1030px;
  348. .list {
  349. >li {
  350. width: 100%;
  351. height: auto;
  352. overflow: hidden;
  353. border-bottom: 1px dashed #ccc;
  354. margin-top: 30px;
  355. padding-bottom: 30px;
  356. a {
  357. color: #337ab7;
  358. text-decoration: none;
  359. display: block;
  360. width: 100%;
  361. height: 22px;
  362. line-height: 22px;
  363. font-size: 20px;
  364. font-weight: bold;
  365. color: #333;
  366. overflow: hidden;
  367. word-break: keep-all;
  368. white-space: nowrap;
  369. overflow: hidden;
  370. text-overflow: ellipsis;
  371. }
  372. p {
  373. a {
  374. width: 100%;
  375. height: 72px;
  376. line-height: 24px;
  377. overflow: hidden;
  378. font-size: 14px;
  379. color: #666;
  380. font-weight: normal;
  381. }
  382. }
  383. }
  384. }
  385. }
  386. .listBoxRight {
  387. width: 315px;
  388. overflow: hidden;
  389. }
  390. }
  391. }
  392. //分页
  393. .pagination {
  394. height: 34px;
  395. display: flex;
  396. justify-content: center;
  397. margin: 0;
  398. width: 100%;
  399. overflow: hidden;
  400. margin: 20px 0;
  401. padding: 20px 0;
  402. // 鼠标移入后字体颜色
  403. .el-pagination::v-deep :hover {
  404. color: #139609;
  405. }
  406. .el-pagination.is-background::v-deep .btn-next,
  407. .el-pagination.is-background::v-deep .btn-prev {
  408. width: 70px;
  409. height: 34px;
  410. margin: 0px 10px;
  411. border-radius: 4px;
  412. }
  413. .el-pagination.is-background::v-deep .el-pager li {
  414. margin: 0px 10px;
  415. width: 38px;
  416. height: 34px;
  417. border-radius: 4px;
  418. }
  419. .el-pagination.is-background::v-deep .btn-next.is-active,
  420. .el-pagination.is-background::v-deep .btn-prev.is-active,
  421. .el-pagination.is-background::v-deep .el-pager li.is-active {
  422. background-color: #337ab7;
  423. color: #fff;
  424. }
  425. .total {
  426. display: block;
  427. height: 34px;
  428. line-height: 34px;
  429. font-size: 18px;
  430. margin-left: 20px;
  431. }
  432. }
  433. </style>